/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package example.hello;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author doo
 */
@WebServlet(name = "Details", urlPatterns = {"/Details"})
public class Details extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method. Méthode GET de la servlet. Elle ne consiste qu'à
     * rediriger vers la page principale, pour le moment.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);

        // Redirection vers le formulaire index.jsp
        getServletContext().getRequestDispatcher("/index.jsp")
                .forward(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method. Méthode POST de la servlet, utilisé lorsqu'on
     * appuie sur le bouton de validation du formulaire.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
//        System.out.println("lamethodequivabienpourrécupererlamethodehttp");
        processRequest(request, response);
        ResultSet liste = null;
        InterfaceSQL requete = new InterfaceSQL();

//        System.out.println(request.getParameter("id"));  
        String id = request.getParameter("id");
        String detail = "SELECT * FROM monito.grossetable WHERE id=" + id + ";";
        try {
            requete.sendReq(InterfaceSQL.TypeReq.select, detail);
            liste = requete.getResultSet();
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println(" <head>");

            while (liste.next()) {
                String temp = liste.getString("methode");
                System.out.println(temp);
                String temp2 = liste.getString("id");
                String temp3 = liste.getString("resultat");
                out.println("<br />");
                out.println(temp);
                out.println(temp2);
                out.println(temp3);
//                out.println(detail);
            }
            out.println("<br />");

            out.println("<br />");
            out.println("<a href=\"index.jsp\">Retour</a>");
            out.println("</html>");
            out.println(" </head>");
        } catch (SQLException ex) {
            Logger.getLogger(List.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
